package supercafe.core;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ItemNoteScreen extends Activity {
    private EditText et;

    /*
     * (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.item_note_dialog);
        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        
        // title
        try {
            String s = getIntent().getExtras().getString("title");
            if (s.length() > 0) {
                this.setTitle(s);
            }
        } catch (Exception e) {
        }
        // value

        try {
            et = ((EditText) findViewById(R.id.etxtNoteInput));
            et.setText(getIntent().getExtras().getString("value"));
        } catch (Exception e) {
        }
        // button
        ((Button) findViewById(R.id.btnSubmitNote)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				executeDone();
			}
        });
        ((Button) findViewById(R.id.btnCancelNote)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setResult(Activity.RESULT_CANCELED);
		        finish();
			}
        });
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onBackPressed()
     */
    public void onBackPressed() {
        //super.onBackPressed();
        executeDone();
    }


    private void executeDone() {
        Intent resultIntent = new Intent();
        resultIntent.putExtra("note", ItemNoteScreen.this.et.getText().toString().trim());
        setResult(Activity.RESULT_OK, resultIntent);
        finish();
    }


}
